package cn.edu.scau.cmi.yangzemin.client;
import cn.edu.scau.cmi.yangzemin.composite.consistent.ConsistentOrganization;
import cn.edu.scau.cmi.yangzemin.composite.consistent.ConsistentPerson;
import cn.edu.scau.cmi.yangzemin.composite.consistent.ConsistentTeam;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class ConsistentCompositeClient {
	static ConsistentCompositeClient consistentCompositeClient =new ConsistentCompositeClient();
	 static void createTeam() {
		companyName.setName("Welcome to Car company ");
		
		System.out.print("please input the teamName: ");
		Scanner scanner=new Scanner(System.in);
		String teamName=scanner.next();
		ConsistentTeam consistentTeam=new ConsistentTeam();
		consistentTeam.setName(teamName);
		
		System.out.print("please input the number of people in this team: ");
		int number=scanner.nextInt();
		for(int i=0;i<number;i++) {
			System.out.print("please input the person name: ");
			String personName=scanner.next();	
			ConsistentPerson person=new ConsistentPerson(personName);
			consistentTeam.addOrganization(person);	
		}
		
		teamMap.put(teamName,consistentTeam);
		companyName.addOrganization(consistentTeam);
		companyName.getTeam(1);
	}
	 
	public static void add(ConsistentTeam stToChange) {
		System.out.print("please input the person name: ");
		Scanner scanner=new Scanner(System.in);
		String personName=scanner.next();	
		ConsistentPerson cperson=new ConsistentPerson(personName);
		stToChange.addOrganization(cperson);
	}
	
	public static void remove(ConsistentTeam consistentTeam) {
		System.out.print("please input the person name: ");
		Scanner scanner=new Scanner(System.in);
		String personName=scanner.next();	
		ConsistentOrganization consistentOrganization=consistentTeam.searchOrganization(personName);
		consistentTeam.removeOrganization(consistentOrganization);
	}
	
	public  void updateTeam() {
		ConsistentTeam consistentTeam;
		System.out.print("please input the teamName: ");
		Scanner scanner=new Scanner(System.in);
		String name=scanner.next();
		consistentTeam=teamMap.get(name);
		while(true) {
		String choice=scanner.next();
		switch(choice) {
		case"1":
			add(consistentTeam);break;
		case"2":
			remove(consistentTeam);break;
		}
		companyName.getTeam(1);
		}
	}
	static ConsistentTeam companyName=new ConsistentTeam();
	public static void otherOperations() {
		while(true) {
		Scanner scanner=new Scanner(System.in);
		System.out.print("input your choice: ");
		String choice=scanner.next();
		switch(choice) {
		case"1":
			consistentCompositeClient.createTeam();break;
		case"2":
			consistentCompositeClient.updateTeam();
			companyName.getTeam(1);break;
		}
		}
		}
	public static void main(String[] args) {
		System.out.println("1. addPerson");
		System.out.println("2. deletePerson");
		createTeam();
		System.out.println("");
		System.out.println("1 creat Team");
		System.out.println("2 update Team");
		otherOperations();
		
	}
	static Map<String,ConsistentTeam> teamMap=new HashMap<String,ConsistentTeam>();
}